package com.itany.springcloud.springcloudsentinelservice8081.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.itany.springcloud.springcloudcommon.vo.ResponseResult;
import com.itany.springcloud.springcloudsentinelservice8081.blockhandler.HelloControllerBlockHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class HelloController {


    public ResponseResult helloBlockHandler(BlockException e){
        return ResponseResult.fail("helloBlockHandler处理异常",e);
    }


    @RequestMapping("/hello")
    @SentinelResource(value = "hello",blockHandler = "helloBlockHandler")
    public ResponseResult hello(){
        System.out.println("HelloController.hello()");
        return ResponseResult.success();
    }

    @RequestMapping("/hello2")
    @SentinelResource(value = "hello2",blockHandlerClass = HelloControllerBlockHandler.class,blockHandler = "blockHandler")
    public ResponseResult hello2(){
        System.out.println("HelloController.hello2()");
        return ResponseResult.success();
    }
}
